package net.yiny.scrummer.ui.storyboard

import groovy.swing.SwingBuilder
import java.awt.Color
import net.miginfocom.swing.MigLayout

public class ContainerBuilder {

    def children = []
    def listeners = []
    String layoutConstraints = ''

    ContainerBuilder() {}

    ContainerBuilder(layoutConstraints) {
        this.layoutConstraints = layoutConstraints
    }

    def addListener(listener) {
        listeners += listener
    }

    def initialise() {
        def layout = new MigLayout(layoutConstraints)
        def swing = new SwingBuilder()
        def panel = swing.panel(layout: layout,
                mouseClicked: {
                    listeners.each {
                        it.mouseClicked?.call()
                    }
                }
        ) {
            children.each {
                panel(it.initialise()) {
                    lineBorder(color: Color.black, parent: true)
                }
            }
        }
        panel
    }
}
